package com.cskaoyan.kpi.etl;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.IOException;

/**
 * @ClassName ETL
 * @Description: Extract-Transform-Load
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/2/14 14:26
 * @Version V1.0
 **/
public class ETL {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration configuration = new Configuration(true);
        Job job = Job.getInstance(configuration);
        job.setJobName("etl");
        job.setJarByClass(ETL.class);
        //设置输入、输出路径
        TextInputFormat.addInputPath(job, new Path(args[0]));
        TextOutputFormat.setOutputPath(job, new Path(args[1]));

        job.setMapperClass(ETLMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        //注意：我们这里面不需要reduce处理，我们目前只需要将ip地址转换成地域即可
        //job.setReducerClass();

        job.waitForCompletion(true);
    }
}
